home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Modules
/
BackSpaceModules
/
Source
/
SpiroFrog
/
SpiroFrogViewPart.m
< prev
next >
Wrap
Text File
|
1994-05-04
|
2KB
|
103 lines
#import "SpiroFrogViewPart.h"
#import "Thinker.h"
#import <appkit/NXImage.h>
#import <appkit/Window.h>
#import <appkit/Panel.h> // for NXRunAlertPanel()
#import <dpsclient/wraps.h>
#import <libc.h>
#import <math.h>
@implementation SpiroFrogView
- oneStep
{
float mx, my;
float xi, yi;
p=n; n=(n+1)%(NUMLINES-1);
erasep=erase;
erase=(n-lper); if(erase<0) erase+=(NUMLINES-1);
if(n>(NUMLINES-1))n=0;
PScurrentmouse(winNum, &mx, &my);
xi=((mx-midx)/urx)*10.0;
yi=((my-midy)/ury)*10.0;
if((count++>500) && (((mx != oldx) && (my != oldy)) || (count>30000))){
count=0;
PSsetgray(0.0);
NXRectFill(&bounds);
}
oldx=mx; oldy=my;
t1[n]=t1[p]+0.2*xi; if(t1[n]>(2*PI)) t1[n]-=(2*PI);
t2[n]=t2[p]+0.2*yi; if(t2[n]>(2*PI)) t2[n]-=(2*PI);
t3[n]=t3[p]+0.01; if(t3[n]>(2*PI)) t3[n]-=(2*PI);
x1[n]=(cos(t1[n])*s1) + (cos(t2[n])*s3) + midx;
yc1[n]=(sin(t1[n])*s2) + (sin(t2[n])*s4) + midy;
PSsetrgbcolor(0.0,0.0,0.0);
PSmoveto(x1[erasep], yc1[erasep]);
PSlineto(x1[erase], yc1[erase]);
PSstroke();
if ([self shouldDrawColor])
PSsetrgbcolor((cos(t1[n])+1.0)/2.0,
(cos(t2[n])+1.0)/2.0,
(cos(t3[n])+1.0)/2.0);
else PSsetrgbcolor(1.0, 1.0, 1.0);
PSmoveto(x1[p], yc1[p]);
PSlineto(x1[n], yc1[n]);
PSstroke();
return self;
}
- initFrame:(NXRect *)frameRect
{
[super initFrame:frameRect];
[self newSize];
winNum=[[self window] windowNum];
return self;
}
- sizeTo:(NXCoord)width :(NXCoord)height
{
[super sizeTo:width :height];
[self newSize];
return self;
}
- newSize
{
urx=bounds.size.width;
ury=bounds.size.height;
midx=urx/2;
midy=ury/2;
n = 0;
t = 0;
// phases of the three points;
p1=0;
p2=(4*PI)/3;
p3=(2*PI)/3;
// starting angle of each point;
t1[0]=0;
t2[0]=p2;
t3[0]=p3;
// s1 and s2 should define an oval that takes up middle 75% of the screen
s1 = midx*0.5; s2 = midy*0.5;
s3 = midx*0.5; s4 = midy*0.5;
// line per is the percentage back that erase steps
lper=NUMLINES-5;
return self;
}
@end